package cn.mdmm.open.common;

import org.apache.commons.lang3.StringUtils;
import org.mybatis.core.interfaces.impl.DefaultNameGenerator;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import cn.modoumama.common.request.ListRequest;
import cn.modoumama.page.Page;

public class PageUtils {
	protected Logger logger = LoggerFactory.getLogger(PageUtils.class);	
	public static Page getPage(ListRequest request,String orderByClause){
		Page page = new Page();
		Integer currPageStr = request.getPage();
		Integer pageSizeStr = request.getRows();
		String property = request.getSort();
		DefaultNameGenerator nameGenerator = new DefaultNameGenerator();
		if (!StringUtils.isBlank(property)) {
			orderByClause = nameGenerator.getGeneratorNameByName(property) + " " + request.getOrder();
		}

		if(currPageStr != null){
			page.setCurrPage(currPageStr);
		}
		if(currPageStr != null){
			page.setPageSize(pageSizeStr);
		}
		page.addCondition("orderByClause", orderByClause);
		return page;
	}

}
